<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>

<!-- Content Header (Page header) -->
<section class="content-header">
	<h1>
		<spring:message code="admin.article.new" />
	</h1>
	<ol class="breadcrumb">
		<li><a href="goHomePage.html"><i class="fa fa-dashboard"></i> <spring:message code="admin.homepage.title" /></a></li>
		<li class="active"><spring:message code="admin.article.title" /></li>
	</ol>
</section>

<!-- Main content -->
<section class="content">
	<div class="row">
		<!-- left column -->
		<div class="col-md-12">
			<!-- general form elements -->
			<div class="box box-primary">
				<div class="box-header">
					<h3 class="box-title">
						<spring:message code="admin.article.select.group" />
					</h3>
				</div>
				<!-- /.box-header -->
				<!-- form start -->
				<form:form role="form" action="createArticle.html" method="post" commandName="article">
					<div class="box-body">
						<div class="form-group">
							<label><spring:message code="admin.article.group" /></label>
							<form:select class="form-control" items="${articleGroups}" path="articelGroupId">
							</form:select>
						</div>
					</div>
					<!-- /.box-body -->
					<div class="box-footer">
						<button class="btn btn-success" type="button" onclick="validateForm()">
							<spring:message code="admin.form.button.submit" />
						</button>
					</div>
				</form:form>
			</div>
			<!-- /.box -->
		</div>
		<!--/.col (right) -->
	</div>
	<!-- /.row -->
</section>

<!-- /.content -->
<script type="text/javascript">
	function validateForm() {
		$
				.ajax({
					url : 'validateArticleGroup.html',
					type : 'POST',
					dataType : 'text',
					data : "id=" + $('#articelGroupId').val(),
					//contentType : "application/json; charset=utf-8",
					success : function(response) {
						if (response == 'success') {
							$('#article').submit();
						} else {
							$('#error-dialog .modal-body').html('<spring:message javaScriptEscape="true" code="admin.article.group.error" />');
							$("#error-dialog").modal('show');
						}
					},
					error : function() {
						$("#error-dialog").modal('show');
					}
				});
	}
</script>
